class TimelineEventsController < ApplicationController
  # GET /timeline_events
  # GET /timeline_events.xml
  def index
    @memorylane=Memorylane.find(params[:memorylane_id])
@timeline_events=  @memorylane.timeline_events.paginate(:page => params[:page],:per_page =>3)

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @timeline_events }
       format.js { render :json => @timeline_events }
    end
 #   @timelines=  Timeline.paginate(:page => params[:page], :order => 'updated_at DESC')
  # @timeline=Timeline.find(params[:timeline_id])
  # @timeline_events =  @timeline.timeline_events
    
     end


    def page_list
    @memorylane=Memorylane.find(params[:id])
@timeline_events=   @memorylane.timeline_events.paginate(:page => params[:page],:per_page =>3)

    respond_to do |format|
      format.xml  { render :xml => @timeline_events }
       format.js { render :json => @timeline_events }
    end
 #   @timelines=  Timeline.paginate(:page => params[:page], :order => 'updated_at DESC')
  # @timeline=Timeline.find(params[:timeline_id])
  # @timeline_events =  @timeline.timeline_events

     end

       def events_list
          @memorylane=Memorylane.find(params[:id])
           @timeline_events=  @memorylane.timeline_events

          respond_to do |format|
     
            format.xml
            
          end



     end






   # GET /timeline_events/1
  # GET /timeline_events/1.xml
  def show

    @timeline_event = TimelineEvent.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @timeline_event }
    end
  end

  # GET /timeline_events/new
  # GET /timeline_events/new.xml
  def new
   @memorylane = Memorylane.find(params[:timeline_id])
    @timeline_event=TimelineEvent.new
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @memorylane }
    end
  end

  # GET /timeline_events/1/edit
  def edit
    @timeline_event = TimelineEvent.find(params[:id])
  end

  # POST /timeline_events
  # POST /timeline_events.xml
  def create
   
    if(params[:link].nil?)
    else
        file= Net::HTTP::MultipartPostFile.new(
        params[:link].original_filename,
        params[:link].content_type,
        params[:link].read
      )
 @photo = facebook_session.user.upload_photo(file, :caption => params[:title])
    end
  
     

     @memorylane = Memorylane.find(params[:memorylane_id])
      @timeline_event = @memorylane.timeline_events.create(params[:timeline_event])
    
    respond_to do |format|
      if @timeline_event.save
        flash[:notice] = 'Your event was successfully created.'
         format.js 
    #    format.html { redirect_to @memorylane }
    #    format.xml  { render :xml => @timeline_event, :status => :created, :location => @timeline_event }
      else
        format.js 
     #  format.html { render :action => "new" }
        format.xml  { render :xml => @timeline_event.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /timeline_events/1
  # PUT /timeline_events/1.xml
  def update
    @timeline_event = TimelineEvent.find(params[:id])

    respond_to do |format|
      if @timeline_event.update_attributes(params[:timeline_event])
        flash[:notice] = 'TimelineEvent was successfully updated.'
        format.html { redirect_to(@timeline_event) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @timeline_event.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /timeline_events/1
  # DELETE /timeline_events/1.xml
  def destroy
    @timeline_event = TimelineEvent.find(params[:id])
    @timeline_event.destroy

    respond_to do |format|
      format.html { redirect_to(timeline_events_url) }
      format.xml  { head :ok }
    end
  end
end
